<?php

namespace app\controller\api;

use app\util\ReturnCode;
use app\model\RailwayStation as RailwayStationModel;
use app\model\CheckType as CheckTypeModel;

class CheckType extends Base
{

    public function lists()
    {
        $id = $this->request->get('sid', 0);
        // railway_station表id
        $station = RailwayStationModel::where(['id' => $id])->find();
        if (empty($station)) {
            return $this->buildFailed(ReturnCode::INVALID, '站点不存在');
        }
        if ($station['status'] < 2) {
            return $this->buildFailed(ReturnCode::INVALID, '站点状态不对');
        }
        if (empty($station['check_ids'])) {
            return $this->buildFailed(ReturnCode::INVALID, '站点没有检查类型');
        }
        // $checkIds = explode(',',$station['check_ids']);
        $lists = CheckTypeModel::where([
            ['status', '=', 1],
            ['id', 'in', $station['check_ids']]
        ])
            ->select()
            ->order('sort desc')
            ->toArray();
        return $this->buildSuccess($lists);
    }
}
